<template>
	<view class="jianli">
		<view class="jianli-box" v-for="(item,index) in userlist" :key="index">
			<view class="content-card" @tap="gomyfrom">
				<uni-card :title="item.name" spacing="0 20%" extra="更改信息" :thumbnail="item.img">
					<view>性别：{{item.sex}}</view>
					<view>联系方式：{{item.phone}}</view>
				</uni-card>
			</view>
			<view class="main-card" v-for="(item,index) in valiFormData" :key="item.id">
				<uni-forms ref="valiForm">
					<view class="title">个人描述</view>
					<uni-forms-item labelWidth="0px" name="description">
						<uni-easyinput v-model="item.description" type="textarea"  />
					</uni-forms-item>
					<view class="title">技术能力</view>
					<uni-forms-item labelWidth="0px" name="skill">
						<uni-easyinput v-model="item.skill" type="textarea"/>
					</uni-forms-item>
				</uni-forms>
				
			</view>
			<text></text>
			<button  type="primary" @click="submit('valiForm')">提交保存</button>
			<button @tap="as">sss</button>
		</view>
	</view>
</template>

<script>
	import axios from "axios"
	import Cookies from "js-cookie"
	import store from "@/store/index.js"
	export default {
		data() {
			return {
				list:[{}],
				// list: [{
				// 	id: 1,
				// 	name: "inb",
				// 	sex: '男',
				// 	img:'/static/img/1.svg',
				// 	phone: '13244445555',
				// 	description: 'ssssssssssssssssss',
				// 	skill: 'tttttttttttttttttttt',
				// }],
				
				// 校验表单数据
				valiFormData: [{

					description: '',
					skill: '',
				}],
				
			}
		},
		computed:{
			userlist(){
				return  uni.getStorageSync('userlist')
			}
			// userlist() {
			// 	return this.$store.state.userlist
			// }
		},
		mounted() {
			const username = Cookies.get('username')
			axios.get("/api/getjianli?username=" + username).then(res=>{
				console.log(res.data);
				this.valiFormData = res.data
				// this.valiFormData.description = res.data[0].description
				// this.valiFormData.skill = res.data[0].skill
			})
			this.list = uni.getStorageInfoSync('userlist')
		},
		methods: {
			as(){
				console.log(this.valiFormData[0].description)
				console.log(this.valiFormData.skill)
			},
			gomyfrom() {
				uni.navigateTo({
					url: '/pages/my/myform/myform'
				})
			},
			submit(ref) {
				const userid = uni.getStorageSync('userjianli')[0].userid
				
				this.$refs[ref][0].validate().then(res => {
					console.log('success', res);
					uni.showToast({
						title: `校验通过`
					})
				}).then(res =>{
					const description = this.valiFormData[0].description
					const skill = this.valiFormData[0].skill
					axios.post('/api/jianli?userid='+userid+
					'&description='+description+
					'&skill='+skill)
					.then(res =>{
						uni.showToast({
							title: `修改成功`
						})
						setTimeout(res =>{
							this.$router.go(0)
						},500)
					})
				})
				.catch(err => {
					// console.log('err', err);
				});
			},
		},
	}
</script>
<style scoped lang="scss">
	.jianli {
		width: 100%;
		height: 100%;
		// padding: 0 10%;
	}

	.main-card {
		width: 100%;
		height: 100%;
		padding: 0 10%;

		.title {
			color: #99CCCC;
			font-size: 32rpx;
			font-weight: bold;
		}

		.content-card {}
	}

	text {
		margin: 0 5px;
	}

	button {
		margin: 0 20%;
	}
	uni-page-wrapper{
		
	}
</style>
